import { BaseWindow } from "../../../component/window/BaseWindow";
import { AnswerItem } from "./AnswerItem";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { RandRewardConfig } from "../../resource/RandRewardConfig";
import { ERandRewardType } from "../../../../Message/Public/ERandRewardType";
import { TRandRewardConfig } from "../../../../Message/Db/Tables/TRandRewardConfig";
import { BaseItemNormal } from "../common/item/BaseItemNormal";
import { ItemData } from "../../resource/info/ItemData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { SGetBossQuestion } from "../../../../Message/Public/SGetBossQuestion";
import { SAnswerBossQuestionRes } from "../../../../Message/Public/SAnswerBossQuestionRes";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class ActiveBossQuestion
    
    export  class ActiveBossQuestion extends BaseWindow
    {
        constructor()
        {
            super();
            this._answerVec = new Vector.<AnswerItem>();
            setSize(330, 370);
            title = Language.getString(35601);
            titleHeight = 25;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(18, 38, 294, 320, this);
            ObjCreate.createBg(30, 105, 270, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(30, 280, 270, 2, this, ImagesConst.SplitLine);
            this._questionLabel = ObjCreate.createGTextField("", 25, 45, 280, 70, this, new GTextFormat(FontUtil.songtiName, 12, GlobalStyle.color2Uint, null, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, null, 5));
            this._questionLabel.wordWrap = true;
            this._questionLabel.multiline = true;
            this._questionLabel.mouseWheelEnabled = false;
            this._answerA = this.createAnswerItem(30, 110);
            this._answerB = this.createAnswerItem(30, 150);
            this._answerC = this.createAnswerItem(30, 190);
            this._answerD = this.createAnswerItem(30, 230);
            this._rightBm = ObjCreate.createBitmap(null, 240, 255, this);
            this._rightBm.visible = false;
            this._wrongBm = ObjCreate.createBitmap(null, 240, 255, this);
            this._wrongBm.visible = false;
            ObjCreate.createLabel(Language.getString(69800), 25, 286, 250, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this.updateRewardItems();
            LoaderHelp.addResCallBack(ResFileConst.questionBoss, this.onResCallBack);
            return;
        }

        /* internal  */updateRewardItems(): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc1=RandRewardConfig.instance.getRewardsByType(ERandRewardType._ERandRewardArenaQuestion);
            loc3 = 0;
            while (loc3 < 6) 
            {
                if (loc3 < loc1.length) 
                {
                    loc2 = loc1[loc3] as TRandRewardConfig;
                    (loc4 = new BaseItemNormal()).setSize(32, 32);
                    loc4.x = 50 + loc3 * 40;
                    loc4.y = 312;
                    loc4.itemData = new ItemData(loc2.code);
                    this.addChild(loc4);
                }
                ++loc3;
            }
            return;
        }

        /* internal  */createAnswerItem(arg1: int, arg2: int): AnswerItem
        {
            var loc1=new AnswerItem();
            loc1.x = arg1;
            loc1.y = arg2;
            loc1.addEventListener(flash.events.Event.CHANGE, this.onAnswerSelect);
            this.addChild(loc1);
            this._answerVec.push(loc1);
            return loc1;
        }

        /* internal  */onAnswerSelect(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.currentTarget as AnswerItem;
            if (loc1.selected) 
            {
                this.disableSelect();
                if (this._question) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildCopyAnswerBossQuestion, {"entityId": this._question.entityId, "answer": loc1.label}));
                }
            }
            else 
            {
                this.enableSelect();
            }
            return;
        }

        /* internal  */onResCallBack(): void
        {
            var loc1=null;
            this._rightBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.qB_rightBg);
            this._wrongBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.qB_wrongBg);
            var loc2=0;
            var loc3=this._answerVec;
            for(loc1 of loc3) 
            {
                loc1.updateRes();
            }
            return;
        }

        /* internal  */disableSelect(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._answerVec;
            for(loc1 of loc3) 
            {
                loc1.selectEnabled = false;
            }
            return;
        }

        /* internal  */enableSelect(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._answerVec;
            for(loc1 of loc3) 
            {
                loc1.selectEnabled = true;
            }
            return;
        }

        /* internal  */clearQues(): void
        {
            var loc1=null;
            this._questionLabel.htmlText = "";
            var loc2=0;
            var loc3=this._answerVec;
            for(loc1 of loc3) 
            {
                loc1.clear();
            }
            this._rightBm.visible = false;
            this._wrongBm.visible = false;
            return;
        }

        public updateQuestion(arg1: SGetBossQuestion): void
        {
            this.clearQues();
            this.startTimer();
            this._question = arg1;
            this._questionLabel.htmlText = arg1.questionName;
            this._answerA.label = arg1.a;
            this._answerB.label = arg1.b;
            this._answerC.label = arg1.c;
            this._answerD.label = arg1.d;
            return;
        }

        public showQuestionResult(arg1: SAnswerBossQuestionRes): void
        {
            var loc1=null;
            this.disableSelect();
            var loc2=0;
            var loc3=this._answerVec;
            for(loc1 of loc3) 
            {
                if (loc1.label == arg1.rightAnswer) 
                {
                    loc1.showTips = true;
                    continue;
                }
                loc1.showTips = false;
            }
            if (arg1.isRight) 
            {
                this._rightBm.visible = true;
                this._wrongBm.visible = false;
            }
            else 
            {
                this._rightBm.visible = false;
                this._wrongBm.visible = true;
            }
            return;
        }

        /* internal  */startTimer(): void
        {
            if (!this._timer) 
            {
                this._timer = new SecTimer();
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerEvent);
                this._timer.addListener(TimerType.COMPLETE, this.onTimerComplete);
            }
            this._timer.reset();
            this._timer.repeatCount = 20;
            this._timer.start();
            return;
        }

        /* internal  */stopTimer(): void
        {
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
            }
            return;
        }

        /* internal  */onTimerEvent(arg1: SecTimer): void
        {
            return;
        }

        /* internal  */onTimerComplete(arg1: SecTimer): void
        {
            this.hide();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this.stopTimer();
            this.clearQues();
            return;
        }

        /* internal */ /* var */_question: SGetBossQuestion;

        /* internal */ /* var */_questionLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_answerVec: Vector.<AnswerItem>;

        /* internal */ /* var */_answerA: AnswerItem;

        /* internal */ /* var */_answerB: AnswerItem;

        /* internal */ /* var */_answerC: AnswerItem;

        /* internal */ /* var */_answerD: AnswerItem;

        /* internal */ /* var */_rightBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_wrongBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_timer: SecTimer;
    }
